package bz.ziro.kanbe.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;

@Model
public class Site implements Serializable {

    private static final long serialVersionUID = 1L;

    @Attribute(primaryKey = true)
    private Key key;

    @Attribute(version = true)
    private Long version;

    private Integer schemaVersion = 1;
    
    @Attribute
    private Date publishDate;

    @Attribute
    private String name;
    @Attribute
    private String detail;
    @Attribute
    private String defaultTimezone = "JST";

    @Attribute
    private User creator;
    @Attribute
    private Date createDate;
    @Attribute
    private User editor;
    @Attribute
    private Date editDate;

    @Attribute(persistent = false)
    private String publishDateString;

    /**
     * @return the key
     */
    public Key getKey() {
        return key;
    }

    /**
     * @param key
     */
    public void setKey(Key key) {
        this.key = key;
    }

    /**
     * @return the version
     */
    public Long getVersion() {
        return version;
    }

    /**
     * @param version
     *            the version
     */
    public void setVersion(Long version) {
        this.version = version;
    }

    /**
     * Returns the schema version.
     *
     * @return the schema version
     */
    public Integer getSchemaVersion() {
        return schemaVersion;
    }

    /**
     * Sets the schema version.
     *
     * @param schemaVersion
     *            the schema version
     */
    public void setSchemaVersion(Integer schemaVersion) {
        this.schemaVersion = schemaVersion;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public User getEditor() {
        return editor;
    }

    public void setEditor(User editor) {
        this.editor = editor;
    }

    public Date getEditDate() {
        return editDate;
    }

    public void setEditDate(Date editDate) {
        this.editDate = editDate;
    }
    /**
     * @param publishDate セットする publishDate
     */
    public void setPublishDate(Date publishDate) {
        this.publishDate = publishDate;
    }
    /**
     * @return publishDate
     */
    public Date getPublishDate() {
        return publishDate;
    }


    /**
     * @return publishDate
     */
    public String getPublishDateString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        if ( publishDate == null ) {
            return "";
        }
        publishDateString = sdf.format(publishDate);
        return publishDateString;
    }

	/**
	 * @param defaultTimezone the defaultTimezone to set
	 */
	public void setDefaultTimezone(String defaultTimezone) {
		this.defaultTimezone = defaultTimezone;
	}

	/**
	 * @return the defaultTimezone
	 */
	public String getDefaultTimezone() {
		return defaultTimezone;
	}

}
